using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace TestWidget
{
    public partial class WidgetContainer : System.Web.UI.UserControl
    {
        private WidgetInstance _widgetInstance;
        public WidgetContainer()
        {
            _widgetInstance = new WidgetInstance();
        }
        public WidgetInstance WidgetInstance
        {
            set { _widgetInstance = value; }
            get { return _widgetInstance; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Literal lt = new Literal();
            liTitle.Text = WidgetInstance.Title;
            lt.Text = WidgetInstance.Content+"<br />";
            lt.ID = "Widget" + WidgetInstance.Id.ToString();
            if (!string.IsNullOrEmpty(WidgetInstance.Url))
            {
                System.Web.UI.Control ct = LoadControl(WidgetInstance.Url);
                ct.ID = "Widget" + WidgetInstance.Id.ToString();
                PanelBody.Controls.Add(ct);
            }
            else
            {
                PanelBody.Controls.Add(lt);
            }
        }

        protected void EditWidget_Click(object sender, EventArgs e)
        {

        }

        protected void CollapseWidget_Click(object sender, EventArgs e)
        {

        }

        protected void ExpandWidget_Click(object sender, EventArgs e)
        {

        }

        protected void CloseWidget_Click(object sender, EventArgs e)
        {

        }

        public override void RenderControl(HtmlTextWriter writer)
        {
            writer.AddAttribute("InstanceId", this.WidgetInstance.Id.ToString());
            base.RenderControl(writer);
        }
    }
}